/*
 * Class name: EntityCreator.java
 * Version: 1.0
 * Date: 10.10. 2013
 */
package cz.muni.fi.pa165.soccergamesarchive.persistencelayer.utils;

import cz.muni.fi.pa165.soccergamesarchive.persistencelayer.entities.Player;
import cz.muni.fi.pa165.soccergamesarchive.persistencelayer.entities.SoccerMatch;
import cz.muni.fi.pa165.soccergamesarchive.persistencelayer.entities.Team;
import java.util.ArrayList;
import java.util.List;

import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;

/**
 * Class creates entity Team and Player for testing purposes
 *
 * @author Michal Ďuriš
 */
public class EntityCreator {

    public static List<Team> createTeams(int teamsCount) {
        List<Team> teams = new ArrayList<>(teamsCount);

        for (int i = 0; i < teamsCount; i++) {
            teams.add(createTeam());
        }

        return teams;
    }

    public static List<Team> createTeamsWithIDs(int teamsCount) {
        List<Team> teams = new ArrayList<>(teamsCount);

        for (int i = 0; i < teamsCount; i++) {
            teams.add(createTeamWithID(new Long(i + 1)));
        }

        return teams;
    }

    public static Team createTeam() {
        Team team = new Team();

        team.setName(randomAlphabetic(11));
        team.setManagerName(randomAlphabetic(7));
        team.setPlayers(createSquad(team));

        return team;
    }

    public static Team createTeamWithID(Long id) {
        Team team = new Team();

        team.setName(randomAlphabetic(11));
        team.setManagerName(randomAlphabetic(7));
        team.setPlayers(createSquadWithIDs(team));
        team.setId(id);

        return team;
    }

    public static List<Player> createSquad(Team team) {
        List<Player> squad = new ArrayList<>(11);

        for (int i = 0; i < 11; i++) {
            squad.add(i, createPlayerWithoutShirtNumber(team));
            squad.get(i).setShirtNumber(i + 1);
        }

        return squad;
    }

    public static List<Player> createSquadWithIDs(Team team) {
        List<Player> squad = new ArrayList<>(11);

        for (int i = 0; i < 11; i++) {
            squad.add(i, createPlayerWithoutShirtNumber(team));
            squad.get(i).setShirtNumber(i + 1);
            squad.get(i).setId(new Long(i + 1));
        }

        return squad;
    }

    private static Player createPlayerWithoutShirtNumber(Team team) {
        Player player = new Player();

        player.setFirstName(randomAlphabetic(7));
        player.setLastName(randomAlphabetic(11));
        player.setTeam(team);

        return player;
    }

    public static List<SoccerMatch> createSoccerMatches(int count, Team homeTeam,
                                                        Team awayTeam) {
        List<SoccerMatch> soccerMatchList = new ArrayList<>();

        for (int i = 0; i < count; i++) {
        }

        return null;
    }

    public static SoccerMatch createSoccerMatch(Team homeTeam, Team awayTeam) {

        return null;
    }

}
